from django.db import models
from  db.base_model import BaseModel
from tinymce.models import HTMLField

# Create your models here.
class GoodsType(BaseModel):
    '''商品种类'''
    name = models.CharField(max_length=50, verbose_name="种类名称")
    logo = models.CharField(max_length=50, verbose_name="logo")
    image = models.ImageField(upload_to='type', verbose_name="图片")

    class Meta:
        db_table = 'df_goods_type'
        verbose_name = '商品种类'
        verbose_name_plural = verbose_name


class GoodsSKU(BaseModel):
    '''商品SKU'''
    status_choices = (
        (0, '上线'),
        (1, '下线')
    )

    type = models.ForeignKey('GoodsType', on_delete=models.CASCADE)
    goods = models.ForeignKey('GoodsSPU', on_delete=models.CASCADE)
    name = models.CharField(max_length=20)
    desc = models.CharField(max_length=256)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    unit = models.CharField(max_length=20)
    stock = models.IntegerField(default=1)
    sales = models.IntegerField(default=0)
    image = models.ImageField(upload_to='goods')
    status = models.SmallIntegerField(default=1, choices=status_choices)

    class Meta:
        db_table = 'df_goods_sku'
        verbose_name = '商品SKU'
        verbose_name_plural = verbose_name


class GoodsSPU(BaseModel):
    '''商品SPU'''
    name = models.CharField(max_length=20)
    detail = HTMLField(blank=True)

    class Meta:
        db_table = 'df_goods_spu'
        verbose_name = '商品SPU'
        verbose_name_plural = verbose_name


class GoodsImage(BaseModel):
    '''商品图片模型类'''
    sku = models.ForeignKey('GoodsSKU', on_delete=models.CASCADE)
    image = models.ImageField(upload_to='goods')

    class Meta:
        db_table = 'df_goods_image'
        verbose_name = '商品图片'
        verbose_name_plural = verbose_name


class IndexGoodsBanner(BaseModel):
    '''商品首页推荐图片'''
    sku = models.ForeignKey('GoodsSKU', on_delete=models.CASCADE)
    image = models.ImageField(upload_to='banner')
    index = models.SmallIntegerField(default=0)

    class Meta:
        db_table = 'df_goods_banner_index'
        verbose_name = '商品首页推荐图片'
        verbose_name_plural = verbose_name


class IndexPromotionBanner(BaseModel):
    '''首页促销活动模型类'''
    name = models.CharField(max_length=20)
    url = models.URLField()
    image = models.ImageField(upload_to='banner')
    index = models.SmallIntegerField(default=0)

    class Meta:
        db_table = 'df_goods_banner_promotion'
        verbose_name = '首页促销活动模型类'
        verbose_name_plural = verbose_name


class IndexTypeGoodsBanner(BaseModel):
    '''首页分类商品展示模型'''
    DISPLAY_TYPE_CHOICES = (
        (0,'标题'),
        (1, '图片')
    )

    type = models.ForeignKey('GoodsType', on_delete=models.CASCADE)
    sku = models.ForeignKey('GoodsSKU', on_delete=models.CASCADE)
    display_type = models.SmallIntegerField(default=1,choices=DISPLAY_TYPE_CHOICES)
    index = models.SmallIntegerField(default=0)

    class Meta:
        db_table = 'df_goods_type_index'
        verbose_name = '首页分类商品展示模型'
        verbose_name_plural = verbose_name